from typing import Iterable
from model.datemodel import DateClass


# 类型转换
def json_data_to_date_set(data):
    date_set = set()
    if data is not None and isinstance(data, Iterable):
        if isinstance(data, list):
            for record in data:
                date = record.get("date")
                lunar = record.get("lunar")
                gregorian = record.get("gregorian")
                week = bool(record.get("week"))
                holiday = bool(record.get("holiday"))
                adjustment = bool(record.get("adjustment"))
                date_obj = DateClass(date, week, holiday, adjustment, gregorian, lunar)
                date_set.add(date_obj)
        elif isinstance(data, dict):
            for value in data.values():
                if isinstance(value, dict):
                    date = value.get("date")
                    lunar = value.get("lunar")
                    gregorian = value.get("gregorian")
                    week = bool(value.get("week"))
                    holiday = bool(value.get("holiday"))
                    adjustment = bool(value.get("adjustment"))
                    date_obj = DateClass(date, week, holiday, adjustment, gregorian, lunar)
                    date_set.add(date_obj)
    return date_set
